<?php
define('RESORCE_PATH', dirname(__DIR__).DIRECTORY_SEPARATOR.'ams-projects'.DIRECTORY_SEPARATOR);
$result = '200';
!isset($_GET['app_code']) ? $result = '400' : FALSE;
!isset($_GET['path']) ? $result = '400' : FALSE;
if ($result == '200') {
	$_conf = parse_ini_file('conf/src.ini',TRUE);
	$app_id = isset($_conf['projects'][$_GET['app_code']]) ? $_conf['projects'][$_GET['app_code']] : '0';
	$file = RESORCE_PATH.$app_id.DIRECTORY_SEPARATOR.'src'.$_GET['path'];
	if (file_exists($file)) {
		//判断mime类型
		header('Content-Type:'.get_mime($file));
		readfile($file);
	}
	else $result = '404';
}

if ($result == '404') header('Not Found', true, 404);
elseif ($result == '400') header('Bad Request', true, 400);


function get_mime($file) {
	$result = FALSE;
	$_mime = [
		'jpg'	=>	'image/jpeg',
		'png'	=>	'image/png',
		'gif'	=>	'image/gif',
		'js'	=>	'application/javascript',
		'json'	=>	'application/json',
		'xml'	=>	'text/xml',
		'html'	=>	'text/html',
	];
	$file = explode('.', $file);
	$ext = array_pop($file);
	if (isset($_mime[$ext])) $result = $_mime[$ext];
	return $result;
}